package com.example.service;

import com.example.entity.Person;
import com.example.mapper.PersonMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 管理员业务处理
 **/
@Service
public class PersonService {

    @Resource
    private PersonMapper personMapper;

    /**
     * 新增
     */
    public void add(Person person) {
        personMapper.insert(person);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        personMapper.deleteById(id);
    }

    /**
     * 修改
     */
    public void updateById(Person person) {
        personMapper.updateById(person);
    }

    /**
     * 根据ID查询
     */
    public Person selectById(Integer id) {
        return personMapper.selectById(id);
    }

    /**
     * 查询所有
     */
    public List<Person> selectAll(Person person) {
        return personMapper.selectList(person);
    }

    /**
     * 分页查询
     */
    public PageInfo<Person> selectPage(Person person, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Person> list = personMapper.selectList(person);
        return PageInfo.of(list);
    }
}